<?php



class func{
	public $link1;
	
	//连接数据库参数
	function __construct($db_host,$db_user,$db_pwd,$db_name,$db_char){
		$this->link1 = mysqli_connect($db_host,$db_user,$db_pwd);
		mysqli_select_db($this->link1,$db_name);
		mysqli_set_charset($this->link1,$db_char);
	}
	
	function select($tableName,$where="",$cols="*",$limit=""){
		if($where!=""){
			$where="where ".$where;
		}
		if($limit!=""){
			$limit="limit ".$limit;
		}
		$sql="select $cols from $tableName $where $limit";
		$re=mysqli_query($this->link1,$sql);
		if($re==FALSE){
			echo "sql拼写有误！！";
			echo $sql;
		}else{
			$arr=array();
			while($row=mysqli_fetch_assoc($re)){
				$arr[]=$row;
			}
			if(empty($arr)){
				//echo "没有符合条件的记录";
			}else{
				return $arr;
			}
		}
	}
	
	//添加
	function add($tableName,$arr){
		$keys=array_keys($arr);
		$keys=join(",", $keys);
		$values=array_values($arr);
		$values="'".join("','",$values)."'";
		$sql="insert into $tableName ($keys) values ($values)";
//		 echo $sql;
		$re=mysqli_query($this->link1,$sql);
		if($re>0){
			return TRUE;	
		}else{
			return FALSE;
		}
	}
	
	
	
}











?>